<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现金额" prop="withdrawalAmount">
        <el-input
          v-model="queryParams.withdrawalAmount"
          placeholder="请输入提现金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实际到账金额" prop="actualAmount">
        <el-input
          v-model="queryParams.actualAmount"
          placeholder="请输入实际到账金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手续费金额" prop="feeAmount">
        <el-input
          v-model="queryParams.feeAmount"
          placeholder="请输入手续费金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现状态" prop="withdrawalStatus">
        <el-select v-model="queryParams.withdrawalStatus" placeholder="请选择提现状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_withdraw_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="提现方式" prop="withdrawalType">
        <el-select v-model="queryParams.withdrawalType" placeholder="请选择提现方式" clearable>
          <el-option
            v-for="dict in dict.type.sys_withdraw_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="收款人姓名" prop="accountName">
        <el-input
          v-model="queryParams.accountName"
          placeholder="请输入收款人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款账号" prop="accountNumber">
        <el-input
          v-model="queryParams.accountNumber"
          placeholder="请输入收款账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户银行名称" prop="bankName">
        <el-input
          v-model="queryParams.bankName"
          placeholder="请输入开户银行名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户支行" prop="bankBranch">
        <el-input
          v-model="queryParams.bankBranch"
          placeholder="请输入开户支行"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="applyTime">
        <el-date-picker clearable
          v-model="queryParams.applyTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核时间" prop="approveTime">
        <el-date-picker clearable
          v-model="queryParams.approveTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理时间" prop="processTime">
        <el-date-picker clearable
          v-model="queryParams.processTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择处理时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="完成时间" prop="completeTime">
        <el-date-picker clearable
          v-model="queryParams.completeTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择完成时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作员姓名" prop="operatorName">
        <el-input
          v-model="queryParams.operatorName"
          placeholder="请输入操作员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易流水号" prop="transactionNo">
        <el-input
          v-model="queryParams.transactionNo"
          placeholder="请输入交易流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第三方支付流水号" prop="thirdPartyNo">
        <el-input
          v-model="queryParams.thirdPartyNo"
          placeholder="请输入第三方支付流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现前余额" prop="balanceBefore">
        <el-input
          v-model="queryParams.balanceBefore"
          placeholder="请输入提现前余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现后余额" prop="balanceAfter">
        <el-input
          v-model="queryParams.balanceAfter"
          placeholder="请输入提现后余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源组织ID" prop="sourceOrgId">
        <el-input
          v-model="queryParams.sourceOrgId"
          placeholder="请输入来源组织ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['money:withdrawal:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['money:withdrawal:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['money:withdrawal:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['money:withdrawal:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="withdrawalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="提现记录ID" align="center" prop="withdrawalId" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="提现金额" align="center" prop="withdrawalAmount" />
      <el-table-column label="实际到账金额" align="center" prop="actualAmount" />
      <el-table-column label="手续费金额" align="center" prop="feeAmount" />
      <el-table-column label="提现状态" align="center" prop="withdrawalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_withdraw_status" :value="scope.row.withdrawalStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="提现方式" align="center" prop="withdrawalType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_withdraw_type" :value="scope.row.withdrawalType"/>
        </template>
      </el-table-column>
      <el-table-column label="收款账户信息" align="center" prop="accountInfo" />
      <el-table-column label="收款人姓名" align="center" prop="accountName" />
      <el-table-column label="收款账号" align="center" prop="accountNumber" />
      <el-table-column label="开户银行名称" align="center" prop="bankName" />
      <el-table-column label="开户支行" align="center" prop="bankBranch" />
      <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="approveTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理时间" align="center" prop="processTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.processTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="completeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.completeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="拒绝原因" align="center" prop="rejectReason" />
      <el-table-column label="备注信息" align="center" prop="remark" />
      <el-table-column label="操作员姓名" align="center" prop="operatorName" />
      <el-table-column label="交易流水号" align="center" prop="transactionNo" />
      <el-table-column label="第三方支付流水号" align="center" prop="thirdPartyNo" />
      <el-table-column label="提现前余额" align="center" prop="balanceBefore" />
      <el-table-column label="提现后余额" align="center" prop="balanceAfter" />
      <el-table-column label="来源组织ID" align="center" prop="sourceOrgId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['money:withdrawal:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['money:withdrawal:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户提现记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="提现金额" prop="withdrawalAmount">
          <el-input v-model="form.withdrawalAmount" placeholder="请输入提现金额" />
        </el-form-item>
        <el-form-item label="实际到账金额" prop="actualAmount">
          <el-input v-model="form.actualAmount" placeholder="请输入实际到账金额" />
        </el-form-item>
        <el-form-item label="手续费金额" prop="feeAmount">
          <el-input v-model="form.feeAmount" placeholder="请输入手续费金额" />
        </el-form-item>
        <el-form-item label="提现状态" prop="withdrawalStatus">
          <el-select v-model="form.withdrawalStatus" placeholder="请选择提现状态">
            <el-option
              v-for="dict in dict.type.sys_withdraw_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提现方式" prop="withdrawalType">
          <el-select v-model="form.withdrawalType" placeholder="请选择提现方式">
            <el-option
              v-for="dict in dict.type.sys_withdraw_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收款账户信息" prop="accountInfo">
          <el-input v-model="form.accountInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="收款人姓名" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入收款人姓名" />
        </el-form-item>
        <el-form-item label="收款账号" prop="accountNumber">
          <el-input v-model="form.accountNumber" placeholder="请输入收款账号" />
        </el-form-item>
        <el-form-item label="开户银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户银行名称" />
        </el-form-item>
        <el-form-item label="开户支行" prop="bankBranch">
          <el-input v-model="form.bankBranch" placeholder="请输入开户支行" />
        </el-form-item>
        <el-form-item label="申请时间" prop="applyTime">
          <el-date-picker clearable
            v-model="form.applyTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核时间" prop="approveTime">
          <el-date-picker clearable
            v-model="form.approveTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理时间" prop="processTime">
          <el-date-picker clearable
            v-model="form.processTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="完成时间" prop="completeTime">
          <el-date-picker clearable
            v-model="form.completeTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="拒绝原因" prop="rejectReason">
          <el-input v-model="form.rejectReason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注信息" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="操作员ID" prop="operatorId">
          <el-input v-model="form.operatorId" placeholder="请输入操作员ID" />
        </el-form-item>
        <el-form-item label="操作员姓名" prop="operatorName">
          <el-input v-model="form.operatorName" placeholder="请输入操作员姓名" />
        </el-form-item>
        <el-form-item label="交易流水号" prop="transactionNo">
          <el-input v-model="form.transactionNo" placeholder="请输入交易流水号" />
        </el-form-item>
        <el-form-item label="第三方支付流水号" prop="thirdPartyNo">
          <el-input v-model="form.thirdPartyNo" placeholder="请输入第三方支付流水号" />
        </el-form-item>
        <el-form-item label="提现前余额" prop="balanceBefore">
          <el-input v-model="form.balanceBefore" placeholder="请输入提现前余额" />
        </el-form-item>
        <el-form-item label="提现后余额" prop="balanceAfter">
          <el-input v-model="form.balanceAfter" placeholder="请输入提现后余额" />
        </el-form-item>
        <el-form-item label="来源组织ID" prop="sourceOrgId">
          <el-input v-model="form.sourceOrgId" placeholder="请输入来源组织ID" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWithdrawal, getWithdrawal, delWithdrawal, addWithdrawal, updateWithdrawal } from "@/api/money/withdrawal"

export default {
  name: "Withdrawal",
  dicts: ['sys_withdraw_type', 'sys_withdraw_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户提现记录表格数据
      withdrawalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        withdrawalAmount: null,
        actualAmount: null,
        feeAmount: null,
        withdrawalStatus: null,
        withdrawalType: null,
        accountInfo: null,
        accountName: null,
        accountNumber: null,
        bankName: null,
        bankBranch: null,
        applyTime: null,
        approveTime: null,
        processTime: null,
        completeTime: null,
        rejectReason: null,
        operatorName: null,
        transactionNo: null,
        thirdPartyNo: null,
        balanceBefore: null,
        balanceAfter: null,
        sourceOrgId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        withdrawalAmount: [
          { required: true, message: "提现金额不能为空", trigger: "blur" }
        ],
        withdrawalStatus: [
          { required: true, message: "提现状态不能为空", trigger: "change" }
        ],
        withdrawalType: [
          { required: true, message: "提现方式不能为空", trigger: "change" }
        ],
        accountInfo: [
          { required: true, message: "收款账户信息不能为空", trigger: "blur" }
        ],
        accountName: [
          { required: true, message: "收款人姓名不能为空", trigger: "blur" }
        ],
        accountNumber: [
          { required: true, message: "收款账号不能为空", trigger: "blur" }
        ],
        applyTime: [
          { required: true, message: "申请时间不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询用户提现记录列表 */
    getList() {
      this.loading = true
      listWithdrawal(this.queryParams).then(response => {
        this.withdrawalList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        withdrawalId: null,
        userId: null,
        withdrawalAmount: null,
        actualAmount: null,
        feeAmount: null,
        withdrawalStatus: null,
        withdrawalType: null,
        accountInfo: null,
        accountName: null,
        accountNumber: null,
        bankName: null,
        bankBranch: null,
        applyTime: null,
        approveTime: null,
        processTime: null,
        completeTime: null,
        rejectReason: null,
        remark: null,
        operatorId: null,
        operatorName: null,
        transactionNo: null,
        thirdPartyNo: null,
        balanceBefore: null,
        balanceAfter: null,
        sourceOrgId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.withdrawalId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加用户提现记录"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const withdrawalId = row.withdrawalId || this.ids
      getWithdrawal(withdrawalId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改用户提现记录"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.withdrawalId != null) {
            updateWithdrawal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addWithdrawal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const withdrawalIds = row.withdrawalId || this.ids
      this.$modal.confirm('是否确认删除用户提现记录编号为"' + withdrawalIds + '"的数据项？').then(function() {
        return delWithdrawal(withdrawalIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('money/withdrawal/export', {
        ...this.queryParams
      }, `withdrawal_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
